<?php


namespace app\order\admin;


use app\admin\controller\Admin;
use app\common\builder\ZBuilder;
use think\Db;
use app\services\models\Orders;

class Order extends Admin
{

    
    public function index(){
        
        $map        = $this->getMap();
        if (!isAdmin()) {
            $map['agency_id']  = getAgencyId();
        }
        $data       = Db::name('orders')->where($map)->paginate();
        return ZBuilder::make('table')
            ->setPageTitle('订单计划列表')
            ->setTableName('orders')
            ->hideCheckbox()
            ->setSearch(['tel','acctname','cardno'])
            ->addColumns([
                ['id','订单ID'],
                ['acctname','姓名'],
                ['bank_name','银行名称'],
                ['cardno','卡号','callback',function($val){return hideMiddle($val); }],             
                ['bill_amount','计划账单金额'],
                ['pay_fee','划扣手续费'],
                ['withdraw_fee','还款手续费'],
                ['total_fee','总手续费'],
                
                ['status','状态',Orders::status_text],
                ['agency_id','上级代理' ,'callback' ,function($val){ return getAgencyInfo($val);}],
                ['created_at','创建时间','callback',function($val){return substr($val,5,16);}],
                ['right_button','操作'],
            ])
            ->addFilter(['status'],Orders::status_text)
            ->addFilter(['type'],Orders::type_text)
            ->addRightButton('custom',[
                'title' => '查看计划详情',
                'icon'  => 'fa fa-fw fa-search',
                'href'  => url('detail',['id'=>'__id__']),
                
            ],['skin' => 'layui-layer-lan' ,'area'=>['1200px','90%']])
            ->setRowList($data)
            ->setPages($data->render())
            ->fetch();

    }


    public function detail($id){
        $data = Db::name('order_details')->where('order_id',$id)->paginate();
        return ZBuilder::make('table')
        ->hideCheckbox()
        ->addColumns([
            ['order_id','订单ID'],
            ['cardno','卡号','callback',function($val){return hideMiddle($val); }],
            ['type','类型',[1=>'划扣',2=>'还款']],         
            ['amount','执行金额'],
            ['fee','手续费'],
            ['status','状态',Orders::status_text],
            ['agency_id','上级代理' ,'callback' ,function($val){ return getAgencyInfo($val);}],
            ['execute_time','执行时间','callback',function($val){return substr($val,5,16);}],
             
        ])
        ->setRowList($data)
        ->setPages($data->render())
        ->fetch();
    }

}